<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>优化高并发场景下的数据库查询性能 - 技术小馆</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #222;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight-box {
            border-left: 4px solid #667eea;
            background-color: #f8fafc;
        }
        .mermaid-tooltip {
            background: rgba(255, 255, 255, 0.9);
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="hero-gradient text-white py-20 px-6">
        <div class="max-w-5xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 animate-fade-in">优化高并发场景下的数据库查询性能</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">构建高性能数据库系统的关键技术与最佳实践</p>
            <div class="flex justify-center space-x-4">
                <a href="#analysis" class="px-6 py-3 bg-white text-indigo-700 font-semibold rounded-lg hover:bg-opacity-90 transition">开始探索</a>
                <a href="#visualization" class="px-6 py-3 border-2 border-white text-white font-semibold rounded-lg hover:bg-white hover:bg-opacity-10 transition">查看图表</a>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="max-w-5xl mx-auto px-6 py-12">
        <!-- Introduction Section -->
        <section class="mb-16">
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">在现代的互联网应用中，随着用户量和访问量的不断增加，高并发成为了许多系统面临的巨大挑战。在这种高并发的场景下，数据库往往是系统瓶颈的所在，因为在多线程同时访问时，数据库的查询性能直接影响到系统的整体响应速度与稳定性。</p>
                
                <div class="my-8 rounded-xl overflow-hidden shadow-lg">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1732945024783-8accaddd-3225-4ad9-a061-1d1db38bf657.png" alt="高并发数据库压力" class="w-full h-auto">
                </div>
                
                <p class="text-lg text-gray-700">因此，优化高并发场景下的数据库查询性能不仅是系统架构设计的重要一环，也是提升用户体验和系统可靠性的关键。</p>
            </div>
        </section>

        <!-- Analysis Section -->
        <section id="analysis" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-search mr-3 text-indigo-600"></i>
                分析性能瓶颈
            </h2>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">在高并发场景下，分析数据库查询的性能瓶颈是优化数据库性能的第一步。了解瓶颈所在能够帮助我们有针对性地采取优化措施，避免无效的优化。</p>
                
                <div class="grid md:grid-cols-2 gap-8 my-8">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4">
                                <i class="fas fa-microscope text-indigo-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">确定瓶颈来源</h3>
                        </div>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>CPU瓶颈：数据库操作大量计算密集型任务</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>内存瓶颈：查询缓存、连接池等导致内存占用过高</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>I/O瓶颈：磁盘或网络带宽不足</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>锁竞争：高并发下数据库锁争用</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>查询效率低：不合理查询或缺乏索引</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4">
                                <i class="fas fa-chart-line text-indigo-600 text-xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">性能监控指标</h3>
                        </div>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-stopwatch text-indigo-500 mt-1 mr-2"></i>
                                <span>查询响应时间</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-tachometer-alt text-indigo-500 mt-1 mr-2"></i>
                                <span>吞吐量</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-plug text-indigo-500 mt-1 mr-2"></i>
                                <span>数据库连接数</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-lock text-indigo-500 mt-1 mr-2"></i>
                                <span>锁等待时间</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-exclamation-triangle text-indigo-500 mt-1 mr-2"></i>
                                <span>慢查询日志</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section id="visualization" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-project-diagram mr-3 text-indigo-600"></i>
                数据库优化全景图
            </h2>
            
            <div class="bg-white p-6 rounded-xl shadow-md">
                <div class="mermaid">
                    graph TD
                    A[高并发数据库优化] --> B[架构优化]
                    A --> C[索引优化]
                    A --> D[查询优化]
                    A --> E[缓存优化]
                    A --> F[连接优化]
                    A --> G[事务与锁优化]
                    
                    B --> B1[分库分表]
                    B --> B2[读写分离]
                    B --> B3[缓存层]
                    B --> B4[高可用]
                    
                    C --> C1[B树索引]
                    C --> C2[哈希索引]
                    C --> C3[联合索引]
                    C --> C4[覆盖索引]
                    
                    D --> D1[避免全表扫描]
                    D --> D2[优化JOIN]
                    D --> D3[批量操作]
                    D --> D4[分页查询]
                    
                    E --> E1[Redis]
                    E --> E2[Memcached]
                    E --> E3[缓存策略]
                    E --> E4[缓存穿透/雪崩]
                    
                    F --> F1[连接池]
                    F --> F2[参数调优]
                    F --> F3[长/短连接]
                    F --> F4[连接泄漏]
                    
                    G --> G1[隔离级别]
                    G --> G2[锁粒度]
                    G --> G3[死锁预防]
                    G --> G4[乐观锁]
                </div>
            </div>
            
            <div class="mt-8 grid md:grid-cols-2 gap-6">
                <div class="highlight-box p-6 rounded-lg">
                    <h3 class="text-xl font-semibold mb-4">关键指标关系</h3>
                    <div class="mermaid">
                        pie
                        title 性能瓶颈分布
                        "CPU瓶颈" : 25
                        "内存瓶颈" : 20
                        "I/O瓶颈" : 30
                        "锁竞争" : 15
                        "查询效率" : 10
                    </div>
                </div>
                
                <div class="highlight-box p-6 rounded-lg">
                    <h3 class="text-xl font-semibold mb-4">优化方案优先级</h3>
                    <div class="mermaid">
                        gantt
                        title 优化实施路线图
                        dateFormat  YYYY-MM-DD
                        section 核心优化
                        索引优化       :done,    des1, 2024-01-01, 30d
                        查询重写       :active,  des2, 2024-02-01, 20d
                        缓存引入       :         des3, 2024-03-01, 25d
                        section 进阶优化
                        分库分表       :         des4, 2024-04-01, 40d
                        读写分离       :         des5, 2024-05-15, 30d
                    </div>
                </div>
            </div>
        </section>

        <!-- Architecture Optimization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-sitemap mr-3 text-indigo-600"></i>
                数据库架构优化
            </h2>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">数据库架构优化是提升数据库性能、提高系统可扩展性和可维护性的关键。随着系统业务规模的不断增长，单一数据库往往无法满足高并发、高可用、高扩展性的需求，因此数据库架构优化至关重要。</p>
                
                <div class="my-8 grid md:grid-cols-2 gap-8">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-database mr-2 text-indigo-500"></i>
                            分库分表策略
                        </h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">垂直分库</h4>
                                <p class="text-gray-700">根据业务模块划分，如用户库、订单库、支付库等，适用于业务逻辑松耦合场景。</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">水平分表</h4>
                                <p class="text-gray-700">按某个维度(如用户ID)拆分数据，适用于大数据量表，提高查询效率。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-exchange-alt mr-2 text-indigo-500"></i>
                            读写分离架构
                        </h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">主从复制</h4>
                                <p class="text-gray-700">写操作指向主库，读操作分散到多个从库，减轻主库压力。</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">负载均衡</h4>
                                <p class="text-gray-700">轮询、加权轮询等策略分配读请求，提升系统吞吐量。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="my-8 bg-indigo-50 p-6 rounded-xl">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-700">缓存优化策略</h3>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                <i class="fas fa-memory mr-2"></i>
                                缓存穿透
                            </h4>
                            <p class="text-gray-700">使用布隆过滤器或空值缓存避免无效查询</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                <i class="fas fa-snowflake mr-2"></i>
                                缓存雪崩
                            </h4>
                            <p class="text-gray-700">设置随机过期时间或使用互斥锁</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2 flex items-center">
                                <i class="fas fa-bolt mr-2"></i>
                                缓存击穿
                            </h4>
                            <p class="text-gray-700">热点数据永不过期或使用双重检查锁</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Index Optimization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-search-plus mr-3 text-indigo-600"></i>
                索引优化
            </h2>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">索引是数据库中提升查询性能的重要工具，可以通过减少全表扫描、加速查询操作，从而显著提高数据库的性能。然而，过度使用索引或不合理的索引设计可能会导致性能问题。</p>
                
                <div class="my-8 grid md:grid-cols-2 gap-8">
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">索引类型选择</h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">B树索引</h4>
                                <p class="text-gray-700">最常用的索引类型，适用于范围查询、排序查询等。</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">哈希索引</h4>
                                <p class="text-gray-700">适用于等值查询，查询速度极快但不支持范围查询。</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-2">全文索引</h4>
                                <p class="text-gray-700">用于全文检索，可查找包含特定单词的记录。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">索引优化策略</h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>为高频查询条件字段创建索引</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>选择选择性高的字段建立索引</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>合理使用联合索引和覆盖索引</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>避免在索引字段上使用函数或计算</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>定期审查和删除无用索引</span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div class="my-8 bg-yellow-50 p-6 rounded-xl border-l-4 border-yellow-400">
                    <h3 class="text-xl font-semibold mb-4 text-yellow-700 flex items-center">
                        <i class="fas fa-exclamation-triangle mr-2"></i>
                        常见索引问题
                    </h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2">索引失效</h4>
                            <p class="text-gray-700">使用不支持索引的操作(如LIKE '%value%')、隐式类型转换或在索引字段上运算会导致索引失效。</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 mb-2">过度索引</h4>
                            <p class="text-gray-700">过多的索引会增加写操作成本，需要根据实际查询模式精简索引。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Query Optimization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-code mr-3 text-indigo-600"></i>
                查询语句优化
            </h2>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">在数据库性能优化中，查询语句的优化至关重要。优化不当的查询语句可以导致数据库执行不必要的操作，造成性能瓶颈，影响系统的响应速度和并发处理能力。</p>
                
                <div class="my-8 grid md:grid-cols-2 gap-8">
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">查询优化原则</h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>避免SELECT *，只查询必要字段</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>使用LIMIT限制返回数据量</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>合理分页避免一次性加载过多数据</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>使用JOIN替代子查询提高效率</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>批量操作减少数据库交互次数</span>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">代码示例</h3>
                        <div class="bg-gray-800 rounded-lg p-4 overflow-x-auto">
                            <pre class="text-gray-200"><code>-- 不推荐: 全表扫描
SELECT * FROM users WHERE YEAR(create_time) = 2023;

-- 推荐: 使用范围查询
SELECT id, name FROM users 
WHERE create_time BETWEEN '2023-01-01' AND '2023-12-31';

-- 不推荐: 使用OR连接多个条件
SELECT * FROM orders 
WHERE status = 'pending' OR status = 'processing';

-- 推荐: 使用IN替代
SELECT * FROM orders 
WHERE status IN ('pending', 'processing');</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Connection Optimization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-plug mr-3 text-indigo-600"></i>
                数据库连接优化
            </h2>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">数据库连接优化是提升数据库性能和系统吞吐量的关键手段之一。在高并发的场景下，数据库连接的创建、使用和释放成为性能瓶颈。有效的数据库连接优化不仅能显著降低延迟和提高响应速度，还能减少数据库资源的消耗。</p>
                
                <div class="my-8 grid md:grid-cols-2 gap-8">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">连接池配置</h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">最大连接数</h4>
                                <p class="text-sm text-gray-600">根据并发量和数据库性能合理设置</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">最小空闲连接</h4>
                                <p class="text-sm text-gray-600">避免频繁创建和销毁连接</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">连接最大等待时间</h4>
                                <p class="text-sm text-gray-600">防止请求长时间阻塞</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">连接测试策略</h4>
                                <p class="text-sm text-gray-600">保证连接有效性</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">连接优化策略</h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>使用高性能连接池(HikariCP)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>合理设置连接超时和回收策略</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>批量操作减少连接占用时间</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span>使用try-with-resources防止连接泄漏</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Transaction Optimization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-lock mr-3 text-indigo-600"></i>
                事务与锁优化
            </h2>
            
            <div class="prose max-w-none">
                <p class="text-lg text-gray-700 mb-6">在高并发的数据库系统中，事务与锁的管理直接影响到系统的性能与可扩展性。事务和锁确保数据的一致性和完整性，但如果使用不当，它们也会成为性能瓶颈。</p>
                
                <div class="my-8 grid md:grid-cols-2 gap-8">
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">事务优化策略</h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">减少事务粒度</h4>
                                <p class="text-sm text-gray-600">将长时间操作分解为小事务</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">选择合适的隔离级别</h4>
                                <p class="text-sm text-gray-600">平衡一致性和性能</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">显式控制事务提交</h4>
                                <p class="text-sm text-gray-600">避免频繁自动提交</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">避免事务中耗时操作</h4>
                                <p class="text-sm text-gray-600">如日志记录、复杂计算</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-indigo-700">锁优化策略</h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">选择合适的锁粒度</h4>
                                <p class="text-sm text-gray-600">行锁 vs 表锁</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">乐观锁与悲观锁</h4>
                                <p class="text-sm text-gray-600">根据场景选择</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">死锁预防</h4>
                                <p class="text-sm text-gray-600">事务顺序一致性</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-gray-800 mb-1">锁超时机制</h4>
                                <p class="text-sm text-gray-600">避免长时间等待</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="my-8 bg-green-50 p-6 rounded-xl border-l-4 border-green-500">
                    <h3 class="text-xl font-semibold mb-4 text-green-700">最佳实践</h3>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div>
                            <h4 class="font-medium text-gray-800 mb-1">短事务原则</h4>
                            <p class="text-sm text-gray-600">尽量减少事务持有时间</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 mb-1">读已提交隔离</h4>
                            <p class="text-sm text-gray-600">高并发下的推荐级别</p>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 mb-1">乐观锁实现</h4>
                            <p class="text-sm text-gray-600">版本号或CAS机制</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="mb-16 bg-indigo-50 p-8 rounded-xl">
            <h2 class="text-3xl font-bold mb-6 text-indigo-700">优化策略总结</h2>
            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="bg-white p-4 rounded-lg shadow-sm">
                    <h3 class="font-semibold text-lg mb-2 flex items-center">
                        <i class="fas fa-archway text-indigo-500 mr-2"></i>
                        架构层面
                    </h3>
                    <ul class="text-sm space-y-1 text-gray-700">
                        <li>分库分表</li>
                        <li>读写分离</li>
                        <li>缓存层</li>
                        <li>高可用设计</li>
                    </ul>
                </div>
                <div class="bg-white p-4 rounded-lg shadow-sm">
                    <h3 class="font-semibold text-lg mb-2 flex items-center">
                        <i class="fas fa-search text-indigo-500 mr-2"></i>
                        查询层面
                    </h3>
                    <ul class="text-sm space-y-1 text-gray-700">
                        <li>索引优化</li>
                        <li>SQL重写</li>
                        <li>批量操作</li>
                        <li>分页查询</li>
                    </ul>
                </div>
                <div class="bg-white p-4 rounded-lg shadow-sm">
                    <h3 class="font-semibold text-lg mb-2 flex items-center">
                        <i class="fas fa-cogs text-indigo-500 mr-2"></i>
                        配置层面
                    </h3>
                    <ul class="text-sm space-y-1 text-gray-700">
                        <li>连接池调优</li>
                        <li>事务配置</li>
                        <li>锁策略</li>
                        <li>监控告警</li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8 px-6">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专业的数据库性能优化指南</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-300 hover:text-white transition flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        访问技术小馆
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-6 border-t border-gray-800 text-center text-sm text-gray-500">
                &copy; 2024 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            gantt: {
                axisFormat: '%Y-%m-%d'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // 卡片悬停效果增强
        const cards = document.querySelectorAll('.card-hover');
        cards.forEach(card => {
            card.addEventListener('mouseenter', () => {
                card.style.transition = 'all 0.3s ease';
            });
        });
    </script>
</body>
</html>